package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.MedicineBean;
import com.project.service.MedicineService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("medicine")
public class MedicineController {
    @Resource
    private MedicineService medicineService;


    //显示所有药剂/器材信息
    @RequestMapping("findAllMedicine")
    @ResponseBody
    public IPage<MedicineBean> findAllMedicine(@RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
                                               @RequestParam(value = "pageSize", defaultValue = "3") int pageSize){
        return medicineService.findAllMedicine(pageNo,pageSize);
    }


    //添加药剂
    @RequestMapping("addMedicine")
    @ResponseBody
    public String addMedicine(MedicineBean medicineBean) {
        medicineService.addMedicine(medicineBean);
        return "ok";
    }

    //模糊查询
    @RequestMapping("findName")
    @ResponseBody
    public IPage<MedicineBean> findName(@RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
                                        @RequestParam(value = "pageSize", defaultValue = "3") int pageSize,
                                        String meName, String meType, String meSort){
        return medicineService.findName(pageNo,pageSize,meName,meType,meSort);
    }
}
